<?php
$this->headTitle()->prepend($this->translate('about_category_description') . ' - ');
$this->headLink()->appendStylesheet($this->APP_STATIC_SERVER . '/skins/admin/default/css/form.css');
$this->headScript()
        ->appendFile($this->APP_STATIC_SERVER . '/js/jquery.validate.js')
        ->appendFile($this->APP_STATIC_SERVER . '/js/rabbit.util.js');
?>
<script type="text/javascript">
    $(document).ready(function(){
        /**
         * Validate form
         */
        $.validator.addMethod('slug', function(value) {
            var regex = new RegExp(/^[a-z0-9\-]+$/);
            if (value.match(regex)) {
                return true;
            } else {
                return false;
            }
        });
        $.validator.addMethod("valueNotEquals", function(value, element, arg){
            return arg != value;
        }, "Value must not equal this.");

        $('#frmAddCategory').validate({
            rules: {
                name: {
                    required: true
                },
                slug: {
                    required: true,
                    slug: true
                },
                module_name: {
                    valueNotEquals: 0
                }
            },
            messages: {
                name: {
                    required: "<?php echo $this->translate('category_name_required'); ?>"
                },
                slug: {
                    required: "<?php echo $this->translate('category_slug_required'); ?>",
                    slug: "<?php echo $this->translate('category_slug_validate'); ?>"
                },
                module_name: {
                    valueNotEquals: "<?php echo $this->translate('category_module_name_required'); ?>"
                }

            }
        });

        
        //điền slug
        $("#name").change(function(){
            $('#slug').val(Rabbit.Util.generateSlug($(this).val()));
        });

    });
</script>

<?php try {
?>
    <div id="r-heading">
        <img src="<?php echo $this->APP_STATIC_SERVER . '/skins/admin/default/images/category.png'; ?>" alt=""/>
        <span><?php echo $this->translate('category_edit_page_title'); ?></span>
    </div>
<?php
    $message = $this->flashMessenger();
    if ($message) {
?>
        <div id="message"><ul><?php echo $message; ?></ul></div>
<?php } ?>
    <form id="frmAddCategory" class="ae-form" enctype="application/x-www-form-urlencoded" accept-charset="utf-8" action="" method="post">
        <div style="width: 60%; float: left;">

            <div class="row">
                <label for="name" class="required"><?php echo $this->translate('category_name'); ?></label>
                <input type="text" name="name" id="name" value="<?php echo $this->category->name ?>" size="50" />
            </div>
            <div class="row">
                <label for="slug" class="required"><?php echo $this->translate('category_slug'); ?></label>
                <input type="text" name="slug" id="slug" value="<?php echo $this->category->slug ?>" size="50" />
            </div>
            <div class="row">
                <label for="module_name" class="required"><?php echo $this->translate('category_module_name'); ?></label>
                <select id="module_name" name="module_name">
                    <option value="0"><?php echo $this->translate('category_module_name_select_option'); ?></option>
                    <option <?php echo ($this->category->module_name == 'news') ? 'selected="selected"' : '' ?> value ="news">News</option>
                    <option <?php echo ($this->category->module_name == 'product') ? 'selected="selected"' : '' ?> value ="product">Product</option>
                </select>
            </div>
            <div class="row">
                <label for="parent_id"><?php echo $this->translate('category_parent'); ?></label>
                <select id="parent_id" name="parent_id">
                    <option value="0"><?php echo $this->translate('category_parent_select_option'); ?></option>
                <?php
                if (isset($this->parentCategories)) {
                    foreach ($this->parentCategories as $parentCategory) {
                ?>
                        <option <?php echo ($parentCategory->id == $this->category->parent_id) ? 'selected="selected"' : '' ?> value ="<?php echo $parentCategory->id ?>"><?php echo $parentCategory->name ?></option>
                <?php
                    }
                }
                ?>
            </select>
        </div>
        <div class="row">
            <label for="language"><?php echo $this->translate('category_language'); ?></label>
            <?php echo $this->languageSelector(array('name' => 'language', 'selected' => $this->category->language)); ?>
            </div>
            <div class="row">
                <label for="sourceItem"><?php echo $this->translate('category_source_item')?></label>
                <div class="translatable">
					<?php
					echo $this->translatableCategory(array(
									'id'       => 'sourceItem',
									'name'     => 'sourceItem',
									'selected' => (null == $this->sourceCategory) ? null : $this->sourceCategory->id,
									'disabled' => null,
								), $this->category->language);
					?>
                </div>
            </div>
            <div class="row">
                <label for="actived"><?php echo $this->translate('category_actived'); ?></label>
                <input type="radio" name="actived" value="1" <?php echo ($this->category->actived) ? 'checked="checked"' : '' ?> /><?php echo $this->translate('common_dialog_confirm_yes'); ?>
                <input type="radio" name="actived" value="0" <?php echo (!$this->category->actived) ? 'checked="checked"' : '' ?> /><?php echo $this->translate('common_dialog_confirm_no'); ?>
            </div>
            <div class="row">
                <label for="featured"><?php echo $this->translate('category_featured'); ?></label>
                <input type="radio" name="featured" value="1" <?php echo ($this->category->featured) ? 'checked="checked"' : '' ?> /><?php echo $this->translate('common_dialog_confirm_yes'); ?>
                <input type="radio" name="featured" value="0" <?php echo (!$this->category->featured) ? 'checked="checked"' : '' ?>/><?php echo $this->translate('common_dialog_confirm_no'); ?>
            </div>
            <div class="row">
                <label for="description" class="optional"><?php echo $this->translate('category_description'); ?></label>
                <textarea name="description" id="description" rows="24" cols="80"><?php echo $this->category->description ?></textarea>
            </div>
        </div>
        <div class="r-right" style="width: 35%; float: right;">
            <div class="box">
                <div class="b-title"><?php echo $this->translate('category_seo') ?></div>
                <div class="b-container">
                    <div class="row">
                        <label for="meta_title" class="optional"><?php echo $this->translate('category_meta_title'); ?></label>
                        <input type="text" name="meta_title" id="meta_title" value="<?php echo $this->category->meta_title ?>" size="50" />
                    </div>
                    <div class="row">
                        <label for="meta_description" class="optional"><?php echo $this->translate('category_meta_description'); ?></label>
                        <textarea name="meta_description" id="meta_description" rows="5" cols="38"><?php echo $this->category->meta_description ?></textarea>
                    </div>
                    <div class="row">
                        <label for="meta_keywords" class="optional"><?php echo $this->translate('category_meta_keywords'); ?></label>
                        <input type="text" name="meta_keywords" id="meta_keywords" value="<?php echo $this->category->meta_keywords ?>" size="50" />
                    </div>
                </div>
            </div>
            <div class="row">
                <input type="submit" name="submit" id="submit" value="<?php echo $this->translate('common_submit'); ?>" class="button" />
                <input type="reset" name="reset" id="reset" value="<?php echo $this->translate('common_reset'); ?>" class="button" />
            </div>
        </div>
    </form>
<?php
            } catch (Exception $ex) {
                echo $ex->getMessage();
            }
?>